package com.qf.blog.controller;

import com.qf.blog.commons.response.ResponseResult;
import com.qf.blog.entity.Comment;
import com.qf.blog.service.ICommentService;
import com.qf.blog.vo.CommentVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping ("/comment")
@Slf4j
public class CommentController {
    @Autowired
    ICommentService iCommentService;

    @PostMapping
    @ResponseBody
    public ResponseResult add(@RequestBody Comment comment) {
        iCommentService.save(comment);
        return ResponseResult.success();
    }

    @GetMapping ("/query")
    public String queryById(Integer postId, HttpServletRequest request) {
        List<CommentVo> commentVoList = iCommentService.queryById(postId);
        request.setAttribute("commentVoList", commentVoList);
        return "site/discuss-detail";
    }
}
